(function($) {
	$.fn.calendar = function(options) {
		defaults = {
			type: null,
			childCell: '',
			year: null,
			month: null,
			hei: null,
			static_month: null,
			day: null,
			callback: function() {} //回调函数;
		};
		return this.each(function() {
			var opts = $.extend(true, defaults, options),
				childCell = opts.childCell,
				year = opts.year,
				month = opts.month,
				day = opts.day,
				callback = opts.callback,
				hei = opts.hei,
				_this = $(this),
				static_month = (new Date().getMonth() + 1);

			//获取一大堆的数据
			var days = new Date(year, month, 0).getDate(), //获取当月天数
				firstWeek = new Date(year + ',' + month + ',' + '01').getDay(), //获取当前月第一天星期几(0-6,0代表星期天)
				lastWeek = new Date(year + ',' + month + ',' + days).getDay(), //获取当前月最后一天星期几(0-6,0代表星期天)
				s_days = new Date(year, month - 1, 0).getDate(), //获取上个月天数
				x_days = new Date(year, month + 1, 0).getDate(); //获取下个月天数
			//添加dom
			var calendar_tit = $('<div class="calendar-tit"></div>').appendTo($(childCell));
			calendar_tit.append('<span class="mui-icon mui-icon-arrowleft calendar-up"></span><span class="calendar-time">' + year + '-' + month + '</span><span class="mui-icon mui-icon-arrowright calendar-down"></span>')
			var calendar_week = $('<ul class="calendar-week mui-clearfix"></ul>').appendTo($(childCell));
			calendar_week.append('<li data-sign="0">日</li><li data-sign="1">一</li><li data-sign="2">二</li><li data-sign="3">三</li><li data-sign="4">四</li><li data-sign="5">五</li><li data-sign="6">六</li>');
			var calendar_date = $('<ul class="calendar-date mui-clearfix"></ul>').appendTo($(childCell))

			//计算上个月
			for(var i = firstWeek; i > 0; i--) {
				$(calendar_date).append('<li class="s_days">' + (s_days - i + 1) + '</li>')
			}
			//计算这个月
			for(var i = 1; i <= days; i++) {

				if(day == i && month == static_month) {
					$(calendar_date).append('<li class="d_days">' + (i) + '</li>')
				} else {
					$(calendar_date).append('<li>' + (i) + '</li>')
				}
			}
			//计算下个月
			var residue_length = 42 - calendar_date.find('li').length;
			for(var i = 1; i <= residue_length; i++) {
				$(calendar_date).append('<li class="x_days">' + i + '</li>')
			}
		});
	}

})(jQuery);